package com.one.monitoring.utils;

import io.minio.MinioClient;
import io.minio.errors.*;
import lombok.extern.slf4j.Slf4j;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

/**
 * @author lxh
 * @description 描述
 * @time 2023/11/17 16:03
 **/
@Slf4j
public class MinioTestUtils {

    public static Integer testMinio(){
        try {
            MinioClient minioClient = new MinioClient("http://16.162.198.48:9000", "admin", "dTi64O28qT");
            // 检查文件夹是否已经存在
            boolean isExist = minioClient.bucketExists("wallet-test");
            if (isExist){
                log.info("minio连接成功");
                return 1;
            }
        } catch (MinioException e) {
            log.info("minio连接异常:{}",e.getMessage());
        } catch (XmlPullParserException e) {
            log.info("minio连接异常:{}",e.getMessage());
        } catch (NoSuchAlgorithmException e) {
            log.info("minio连接异常:{}",e.getMessage());
        } catch (IOException e) {
            log.info("minio连接异常:{}",e.getMessage());
        } catch (InvalidKeyException e) {
            log.info("minio连接异常:{}",e.getMessage());
        }
        return 2;
    }
    public static void main(String[] args) {
        Integer integer = testMinio();
        System.out.println(integer);

    }
}
